import java.util.List;
import java.util.Scanner;




public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		List<Integer> coeffs;
		Scanner scan = new Scanner(System.in);
		int N;
		int isXML;
		double tau;
		double delta;
		double norm;
		String xmlFile;
		Oracle f;
		System.out.println("Welcome to the SFT Algorithm implementation!");
		System.out.println("Type 'go' to use the Algorithm, and 'quit' to exit");
		String userInput = scan.next();
		System.out.println("user input: "+userInput);
		while(userInput.compareTo("quit") != 0){
			System.out.println("Please enter integer N, the size of the abelean group Zn: ");
			do{
				N = scan.nextInt();
				if(N <= 0)
					System.out.println("Group size N must be larger than zero. Try again: ");
			}
			while(N <= 0);
			System.out.println("N: "+N);

			
			System.out.println("Please enter double threshold Tau: ");
			do{
				tau = scan.nextDouble();
				if(tau <= 0)
					System.out.println("Threshold Tau must be larger than zero. Try again: ");
			}
			while(tau <= 0);
			System.out.println("Tau: "+tau);

			
			System.out.println("Please enter double success probability Delta: ");
			do{
				delta = scan.nextDouble();
				if(delta <= 0 || delta >= 1)
					System.out.println("probability Delta must be larger than zero and smaller than 1. Try again: ");
			}
			while(delta <= 0);
			System.out.println("delta: "+delta);


			System.out.println("Please enter 1 to input a function via XML file, or 2 to input a function on-the-fly: ");
			do{
				isXML = scan.nextInt();
				if(isXML != 1 && isXML != 2)
					System.out.println("Please enter 1 to input a function via XML file, or 2 to input a function on-the-fly: ");
			}
			while(isXML != 1 && isXML != 2);
			System.out.println("isXML: "+isXML);

			
			if(isXML == 1){
				System.out.println("Please enter XML file location and name: ");
				xmlFile = scan.next();
				System.out.println("here: "+xmlFile);
				f = new OracleXML(xmlFile, N);
			}
			else{
				f = new OnTheFlyOracle();
			}
			
			System.out.println("Please enter the function's absolute max value: ");
			do{
				norm = scan.nextDouble();
				if(norm <= 0)
					System.out.println("Function's absolute max value must be larger than zero. Try again: ");
			}
			while(norm <= 0);
			
			coeffs = SFT.SFTAlgorithm(N, tau, delta, f, norm);
			System.out.println("The heavy coefficients are: ");
			System.out.println(coeffs.toString());
			
			System.out.println("Type 'go' to use the Algorithm, and 'quit' to exit");
			userInput = scan.next();
		}
		System.out.println("Thank you, Goodbye");
	}

}
